Merge "Move CacheDependency classes to own files"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 8 Mar 2019 21:45:31 +0000 (21:45 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 8 Mar 2019 21:45:31 +0000 (21:45 +0000)
RELEASE-NOTES-1.33
includes/libs/objectcache/BagOStuff.php
includes/libs/objectcache/CachedBagOStuff.php
includes/libs/objectcache/IExpiringStore.php
includes/libs/objectcache/MemcachedBagOStuff.php
includes/libs/objectcache/RedisBagOStuff.php
includes/libs/objectcache/WANObjectCache.php
tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php

index b9331bc..0180763 100644 (file)
@@ -284,6 +284,7 @@ because of Phabricator reports.
 * (T217772) The 'wgAvailableSkins' mw.config key in JavaScript, was removed.
 * Language::markNoConversion, deprecated in 1.32, has been removed. Use
   LanguageConverter::markNoConversion instead.
+* BagOStuff::modifySimpleRelayEvent() method has been removed.
 
 === Deprecations in 1.33 ===
 * The configuration option $wgUseESI has been deprecated, and is expected
index a3c020e..9fa3232 100644 (file)
@@ -87,12 +87,6 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface {
        /** @var int[] Map of (ATTR_* class constant => QOS_* class constant) */
        protected $attrMap = [];
 
-       /** Possible values for getLastError() */
-       const ERR_NONE = 0; // no error
-       const ERR_NO_RESPONSE = 1; // no response
-       const ERR_UNREACHABLE = 2; // can't connect
-       const ERR_UNEXPECTED = 3; // response gave some error
-
        /** Bitfield constants for get()/getMulti() */
        const READ_LATEST = 1; // use latest data for replicated stores
        const READ_VERIFIED = 2; // promise that caller can tell when keys are stale
@@ -729,24 +723,6 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface {
                $this->busyCallbacks[] = $workCallback;
        }
 
-       /**
-        * Modify a cache update operation array for EventRelayer::notify()
-        *
-        * This is used for relayed writes, e.g. for broadcasting a change
-        * to multiple data-centers. If the array contains a 'val' field
-        * then the command involves setting a key to that value. Note that
-        * for simplicity, 'val' is always a simple scalar value. This method
-        * is used to possibly serialize the value and add any cache-specific
-        * key/values needed for the relayer daemon (e.g. memcached flags).
-        *
-        * @param array $event
-        * @return array
-        * @since 1.26
-        */
-       public function modifySimpleRelayEvent( array $event ) {
-               return $event;
-       }
-
        /**
         * @param string $text
         */
index 3927ed3..25fcdb0 100644 (file)
@@ -117,9 +117,5 @@ class CachedBagOStuff extends HashBagOStuff {
                return $this->backend->clearLastError();
        }
 
-       public function modifySimpleRelayEvent( array $event ) {
-               return $this->backend->modifySimpleRelayEvent( $event );
-       }
-
        // @codeCoverageIgnoreEnd
 }
index 7bab20a..c1edff7 100644 (file)
@@ -56,4 +56,9 @@ interface IExpiringStore {
        const QOS_SYNCWRITES_SS = 4; // strict-serializable, nodes refuse reads if possible stale
        // Generic "unknown" value that is useful for comparisons (e.g. always good enough)
        const QOS_UNKNOWN = INF;
+
+       const ERR_NONE = 0; // no error
+       const ERR_NO_RESPONSE = 1; // no response
+       const ERR_UNREACHABLE = 2; // can't connect
+       const ERR_UNEXPECTED = 3; // response gave some error
 }
index bf0da11..47e04d0 100644 (file)
@@ -181,12 +181,4 @@ class MemcachedBagOStuff extends BagOStuff {
        protected function debugLog( $text ) {
                $this->logger->debug( $text );
        }
-
-       public function modifySimpleRelayEvent( array $event ) {
-               if ( array_key_exists( 'val', $event ) ) {
-                       $event['flg'] = 0; // data is not serialized nor gzipped (for memcached driver)
-               }
-
-               return $event;
-       }
 }
index a0febfc..3926604 100644 (file)
@@ -317,14 +317,6 @@ class RedisBagOStuff extends BagOStuff {
                return $result;
        }
 
-       public function modifySimpleRelayEvent( array $event ) {
-               if ( array_key_exists( 'val', $event ) ) {
-                       $event['val'] = serialize( $event['val'] ); // this class uses PHP serialization
-               }
-
-               return $event;
-       }
-
        /**
         * @param mixed $data
         * @return string
index bed7965..41a3e4e 100644 (file)
@@ -214,12 +214,6 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
        const FLD_FLAGS = 4; // key to the flags bitfield (reserved number)
        const FLD_HOLDOFF = 5; // key to any hold-off TTL
 
-       const ERR_NONE = 0; // no error
-       const ERR_NO_RESPONSE = 1; // no response
-       const ERR_UNREACHABLE = 2; // can't connect
-       const ERR_UNEXPECTED = 3; // response gave some error
-       const ERR_RELAY = 4; // relay broadcast failed
-
        const VALUE_KEY_PREFIX = 'WANCache:v:';
        const INTERIM_KEY_PREFIX = 'WANCache:i:';
        const TIME_KEY_PREFIX = 'WANCache:t:';
@@ -237,7 +231,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         * @param array $params
         *   - cache    : BagOStuff object for a persistent cache
         *   - logger   : LoggerInterface object
-        *   - stats    : LoggerInterface object
+        *   - stats    : StatsdDataFactoryInterface object
         *   - asyncHandler : A function that takes a callback and runs it later. If supplied,
         *       whenever a preemptive refresh would be triggered in getWithSetCallback(), the
         *       current cache value is still used instead. However, the async-handler function
@@ -696,16 +690,17 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         * @return bool True if the item was purged or not found, false on failure
         */
        final public function delete( $key, $ttl = self::HOLDOFF_TTL ) {
-               $key = self::VALUE_KEY_PREFIX . $key;
-
                if ( $ttl <= 0 ) {
                        // Publish the purge to all datacenters
-                       $ok = $this->relayDelete( $key );
+                       $ok = $this->relayDelete( self::VALUE_KEY_PREFIX . $key );
                } else {
                        // Publish the purge to all datacenters
-                       $ok = $this->relayPurge( $key, $ttl, self::HOLDOFF_NONE );
+                       $ok = $this->relayPurge( self::VALUE_KEY_PREFIX . $key, $ttl, self::HOLDOFF_NONE );
                }
 
+               $kClass = $this->determineKeyClassForStats( $key );
+               $this->stats->increment( "wanobjectcache.$kClass.delete." . ( $ok ? 'ok' : 'error' ) );
+
                return $ok;
        }
 
@@ -860,7 +855,12 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         */
        final public function touchCheckKey( $key, $holdoff = self::HOLDOFF_TTL ) {
                // Publish the purge to all datacenters
-               return $this->relayPurge( self::TIME_KEY_PREFIX . $key, self::CHECK_KEY_TTL, $holdoff );
+               $ok = $this->relayPurge( self::TIME_KEY_PREFIX . $key, self::CHECK_KEY_TTL, $holdoff );
+
+               $kClass = $this->determineKeyClassForStats( $key );
+               $this->stats->increment( "wanobjectcache.$kClass.ck_touch." . ( $ok ? 'ok' : 'error' ) );
+
+               return $ok;
        }
 
        /**
@@ -892,7 +892,12 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
         */
        final public function resetCheckKey( $key ) {
                // Publish the purge to all datacenters
-               return $this->relayDelete( self::TIME_KEY_PREFIX . $key );
+               $ok = $this->relayDelete( self::TIME_KEY_PREFIX . $key );
+
+               $kClass = $this->determineKeyClassForStats( $key );
+               $this->stats->increment( "wanobjectcache.$kClass.ck_reset." . ( $ok ? 'ok' : 'error' ) );
+
+               return $ok;
        }
 
        /**
@@ -1288,8 +1293,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                $touchedCb = $opts['touchedCallback'] ?? null;
                $initialTime = $this->getCurrentTime();
 
-               // Get a collection name to describe this class of key
-               $kClass = $this->determineKeyClass( $key );
+               $kClass = $this->determineKeyClassForStats( $key );
 
                // Get the current key value
                $curTTL = self::PASS_BY_REF;
@@ -2299,9 +2303,9 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
 
        /**
         * @param string $key String of the format <scope>:<class>[:<class or variable>]...
-        * @return string
+        * @return string A collection name to describe this class of key
         */
-       protected function determineKeyClass( $key ) {
+       protected function determineKeyClassForStats( $key ) {
                $parts = explode( ':', $key );
 
                return $parts[1] ?? $parts[0]; // sanity
index 87c1d1e..017d745 100644 (file)
@@ -1841,14 +1841,14 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase {
 
        /**
         * @dataProvider statsKeyProvider
-        * @covers WANObjectCache::determineKeyClass
+        * @covers WANObjectCache::determineKeyClassForStats
         */
        public function testStatsKeyClass( $key, $class ) {
                $wanCache = TestingAccessWrapper::newFromObject( new WANObjectCache( [
                        'cache' => new HashBagOStuff
                ] ) );
 
-               $this->assertEquals( $class, $wanCache->determineKeyClass( $key ) );
+               $this->assertEquals( $class, $wanCache->determineKeyClassForStats( $key ) );
        }
 }